package com.qgs.secsgem.secs.eq;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qgs.secsgem.secs.SecsException;
import com.qgs.secsgem.secs.SecsMessage;
import com.qgs.secsgem.secs.entity.common.*;
import com.qgs.secsgem.secs.gem.COMMACK;
import com.qgs.secsgem.secs.gem.Clock;
import com.qgs.secsgem.secs.gem.OFLACK;
import com.qgs.secsgem.secs.gem.ONLACK;
import com.qgs.secsgem.secs.hsmsss.HsmsSsCommunicator;
import com.qgs.secsgem.secs.secs2.Secs2;
import com.qgs.secsgem.secs.secs2.Secs2Exception;
import com.qgs.secsgem.secs.secs2.Secs2List;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2023/4/27 10:32
 * 数据符号：
 *      U1       =>  1 个字节无符号整形
 *      U2       =>  2 个字节无符号整形
 *      U3       =>  3 个字节无符号整形
 *      U4       =>  4 个字节无符号整形
 *      I1       =>  1 个字节有符号整形
 *      I2       =>  2 个字节有符号整形
 *      I3       =>  3 个字节有符号整形
 *      I4       =>  4 个字节有符号整形
 *      Binary   =>  二进制
 *      Boolean  =>  bool
 *      F4       =>  4 个字节浮点数
 *      F8       =>  8 个字节浮点数
 *      ASCII    =>  A
 *
 *
 *
 *
 */
public class SECSCommand {

    /***
     *
     * desc:把 VID / ECID / TOTSMP、REPGSZ(S2F23) / RPTID  / CEID / CPNAME(S2F41)  =>   正确的格式（因为每家设备厂家 他们的id类型不一致的）
     *      VID 包括：SVID/DVID
     */
    public static Secs2 getDataId(String value, String vidType){
        if(vidType.equals("A")){
            return Secs2.ascii(value);
        }else if(vidType.equals("U1")){
            return Secs2.uint1(Integer.parseInt(value));
        }else if(vidType.equals("U2")){
            return Secs2.uint2(Integer.parseInt(value));
        }else if(vidType.equals("U4")){
            return Secs2.uint4(Integer.parseInt(value));
        }else if(vidType.equals("U8")){
            return Secs2.uint8(Integer.parseInt(value));
        }else if(vidType.equals("I1")){
            return Secs2.int1(Integer.parseInt(value));
        }else if(vidType.equals("I2")){
            return Secs2.int2(Integer.parseInt(value));
        }else if(vidType.equals("I3")){
            return Secs2.int4(Integer.parseInt(value));
        }else if(vidType.equals("I4")){
            return Secs2.int8(Integer.parseInt(value));
        }else {
            return null;
        }
    }

    public static Secs2 getPPID(String vidValue,String vidType){
        if(vidType.equals("A")){
            return Secs2.ascii(vidValue);
        }else if(vidType.equals("Binary")){

            return Secs2.binary(Byte.parseByte(vidValue));
        }else {
            return null;
        }
    }

    public static Secs2 getDataId(String vidType){
        if(vidType.equals("U1")){
            return Secs2.uint1();
        }else if(vidType.equals("U2")){
            return Secs2.uint2();
        }else if(vidType.equals("U4")){
            return Secs2.uint4();
        }else if(vidType.equals("U8")){
            return Secs2.uint8();
        }else if(vidType.equals("I1")){
            return Secs2.int1();
        }else if(vidType.equals("I2")){
            return Secs2.int2();
        }else if(vidType.equals("I3")){
            return Secs2.int4();
        }else if(vidType.equals("I4")){
            return Secs2.int8();
        }else {
            return null;
        }
    }

    public static Secs2 getDataId(int[] value,String vidType){
        if(vidType.equals("U1")){
            return Secs2.uint1(value);
        }else if(vidType.equals("U2")){
            return Secs2.uint2(value);
        }else if(vidType.equals("U4")){
            return Secs2.uint4(value);
        }else if(vidType.equals("U8")){
            return Secs2.uint8(value);
        }else if(vidType.equals("I1")){
            return Secs2.int1(value);
        }else if(vidType.equals("I2")){
            return Secs2.int2(value);
        }else if(vidType.equals("I3")){
            return Secs2.int4(value);
        }else if(vidType.equals("I4")){
            return Secs2.int8(value);
        }else {
            return null;
        }
    }

    /***
     * desc: CPVALUE(S2F41) => 转化为正确的格式
     */
    public static Secs2 getCPVALUE(String value, String vidType){
        if(vidType.equals("A")){
            return Secs2.ascii(value);
        }else if(vidType.equals("U1")){
            return Secs2.uint1(Integer.parseInt(value));
        }else if(vidType.equals("I1")){
            return Secs2.int1(Integer.parseInt(value));
        }else {
            return null;
        }
    }

    /***
     *
     * desc: RCMD => 转化为正确的格式
     *
     */
    public static Secs2 getRCMD(String value, String vidType){
        if(vidType.equals("Binary")){
            return Secs2.binary(Byte.parseByte(value));
        }else if(vidType.equals("Boolean")){
            return Secs2.bool(Boolean.parseBoolean(value));
        }else if(vidType.equals("A")){
            return Secs2.ascii(value);
        }else if(vidType.equals("U1")){
            return Secs2.uint1(Integer.parseInt(value));
        }else if(vidType.equals("U2")){
            return Secs2.uint2(Integer.parseInt(value));
        }else if(vidType.equals("U4")){
            return Secs2.uint4(Integer.parseInt(value));
        }else if(vidType.equals("U8")){
            return Secs2.uint8(Integer.parseInt(value));
        }else if(vidType.equals("I1")){
            return Secs2.int1(Integer.parseInt(value));
        }else if(vidType.equals("I2")){
            return Secs2.int2(Integer.parseInt(value));
        }else if(vidType.equals("I3")){
            return Secs2.int4(Integer.parseInt(value));
        }else if(vidType.equals("I4")){
            return Secs2.int8(Integer.parseInt(value));
        }else {
            return null;
        }
    }

    /***
     *
     * desc: ALID => 转化为正确的格式
     *
     */
    public static Secs2 getALID(String value, String vidType){
        if(vidType.equals("U1")){
            return Secs2.uint1(Integer.parseInt(value));
        }else if(vidType.equals("U2")){
            return Secs2.uint2(Integer.parseInt(value));
        }else if(vidType.equals("U4")){
            return Secs2.uint4(Integer.parseInt(value));
        }else if(vidType.equals("U8")){
            return Secs2.uint8(Integer.parseInt(value));
        }else if(vidType.equals("I1")){
            return Secs2.int1(Integer.parseInt(value));
        }else if(vidType.equals("I2")){
            return Secs2.int2(Integer.parseInt(value));
        }else if(vidType.equals("I3")){
            return Secs2.int4(Integer.parseInt(value));
        }else if(vidType.equals("I4")){
            return Secs2.int8(Integer.parseInt(value));
        }else {
            return null;
        }
    }

    /***
     *
     * desc:把 ECValue  =>   正确的格式（因为每家设备厂家 他们的id类型不一致的）
     *
     */
    public static Secs2 getDataId(ECNode node){
        String ecvType = node.getEcvType();
        if(ecvType.equals("Binary")){
            return Secs2.binary(Byte.parseByte(node.getEcv()));
        }else if(ecvType.equals("Boolean")){
            return Secs2.bool(Boolean.parseBoolean(node.getEcv()));
        }else if(ecvType.equals("A")){
            return Secs2.ascii(node.getEcv());
        }else if(ecvType.equals("Boolean")){
            return Secs2.bool(Boolean.parseBoolean(node.getEcv()));
        }else if(ecvType.equals("U1")){
            return Secs2.uint1(Integer.parseInt(node.getEcv()));
        }else if(ecvType.equals("U2")){
            return Secs2.uint2(Integer.parseInt(node.getEcv()));
        }else if(ecvType.equals("U4")){
            return Secs2.uint4(Integer.parseInt(node.getEcv()));
        }else if(ecvType.equals("U8")){
            return Secs2.uint8(Integer.parseInt(node.getEcv()));
        }else if(ecvType.equals("I1")){
            return Secs2.int1(Integer.parseInt(node.getEcv()));
        }else if(ecvType.equals("I2")){
            return Secs2.int2(Integer.parseInt(node.getEcv()));
        }else if(ecvType.equals("I3")){
            return Secs2.int4(Integer.parseInt(node.getEcv()));
        }else if(ecvType.equals("I4")){
            return Secs2.int8(Integer.parseInt(node.getEcv()));
        }else if(ecvType.equals("F4")){
            return Secs2.float4(Float.parseFloat(node.getEcv()));
        }else if(ecvType.equals("F8")){
            return Secs2.float8(Float.parseFloat(node.getEcv()));
        }else {
            return null;
        }
    }

    /***
     *
     * desc:把 TRID  =>   正确的格式（因为每家设备厂家 他们的id类型不一致的）
     *
     */
    public static Secs2 getTRId(String value,String type){

        if(type.equals("A")){
            return Secs2.ascii(value);
        }else if(type.equals("U1")){
            return Secs2.uint1(Integer.parseInt(value));
        }else if(type.equals("U2")){
            return Secs2.uint2(Integer.parseInt(value));
        }else if(type.equals("U4")){
            return Secs2.uint4(Integer.parseInt(value));
        }else if(type.equals("U8")){
            return Secs2.uint8(Integer.parseInt(value));
        }else {
            return null;
        }
    }

    public static List<ValueNode> get(JSONArray argList){
        List<ValueNode> set = new ArrayList<>();

        for(int i=0;i<argList.size();i++){
            if(argList.get(i) == null){
                continue;
            }
            JSONObject j = (JSONObject) argList.get(i);
            String type = j.getString("f");
            if(!type.equals("L")){
                set.add(new ValueNode(j.getString("f"),j.get("v").toString()));

            }else {
                //当嵌套里面还有嵌套，，这里顺序错了，修复一下。
                JSONArray array = j.getJSONArray("v");
                set.add(new ValueNode("List",get(array)));
            }
        }
        return set;
    }
    /**
     * SxFy : s1f3
     * desc : 改变一个或者多个 设备常量的值
     * */
    public static Optional<SecsMessage> queryEQPStatus(List<String> vidList, String vidType, HsmsSsCommunicator comm) throws InterruptedException, SecsException {

        List<Secs2> ll = new ArrayList<>();
        for(String vid:vidList){
            ll.add(getDataId(vid,vidType));
        }
        

        return comm.send(1, 3, true, Secs2.list(ll));
    }

    //如果vidList 长度为0, 就是查询所有的SV
    public static Optional<SecsMessage> querySVNameList(List<String> vidList,String vidType, HsmsSsCommunicator comm) throws InterruptedException, SecsException {

        if(vidList.size()==0){
            return comm.send(1, 11, true, Secs2.list());
        }else {
            List<Secs2> ll = new ArrayList<>();
            for(String vid:vidList){
                ll.add(getDataId(vid,vidType));
            }

            return comm.send(1, 11, true, Secs2.list(ll));
        }

    }

    /**
     * SxFy : s2f15
     * desc : 改变一个或者多个 设备常量的值
     * */
    public static Optional<SecsMessage> newEquipmentConstantSend(List<ECNode> ecNodes, String ecidType, HsmsSsCommunicator comm) throws InterruptedException, SecsException {

        if(ecNodes.size()==0){
            return null;
        }else {

            List<Secs2> ll = new ArrayList<>();
            for(ECNode node:ecNodes){

                Secs2 l = Secs2.list(
                        getDataId(node.getEcid(),ecidType)
                        , getDataId(node)
                );
                ll.add(l);

            }
            
            return comm.send(2, 15, true, Secs2.list(ll));
        }
    }

    /**
     * SxFy : s2f17
     * desc : 请求设备当前时间
     * */
    public static Clock dateAndTimeRequest(HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {
        return comm.gem().s2f17();
    }
    /**
     * SxFy : s2f23
     * desc : 设置需要trace 的变量（Trace Initial Send）
     * */
    public static Optional<SecsMessage> traceInitialSend(TraceNode node, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {


        if(node.getVidList().size()==0){
            return null;
        }else {
            List<Secs2> ll = new ArrayList<>();
            //TRID
            ll.add(getTRId(node.getTrid(),node.getTridType()));
            //DSPER
            ll.add(Secs2.ascii(node.getDsper()));
            //TOSTMP
            ll.add(getDataId(node.getTotsmp().toString(),node.getTotsmpType()));
            //REPGSZ
            ll.add(getDataId(node.getRepgsz().toString(),node.getRepgszType()));


//            Secs2 vidList = Secs2.list();
            List<Secs2> vidList = new ArrayList<>();
            for(String vid:node.getVidList()){

                vidList.add(getDataId(vid,node.getVidType()));

            }

            ll.add(Secs2.list(vidList));
            
            return comm.send(2, 23, true, Secs2.list(ll));
        }
    }

    /**
     * SxFy : s2f29
     * desc : 依据ECID ，查询EC相应的信息。
     * */
    public static Optional<SecsMessage> equipmentConstantNameListRequest(List<String> ecids,String ecidType, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {


        if(ecids.size()==0){
            return null;
        }else {
            List<Secs2> ecidList = new ArrayList<>();
            for(String ecid:ecids){
                ecidList.add(getDataId(ecid,ecidType));
            }
            
            return comm.send(2, 29, true, Secs2.list(ecidList));
        }
    }

    /**
     * SxFy : s2f33
     * desc : define report
     * */
    public static Optional<SecsMessage> defineReport(List<ReportNode> reportNodes, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {


        List<Secs2> ll = new ArrayList<>();
        //dataid
        ll.add(Secs2.uint2(1));
        Secs2[] rptList = new Secs2[reportNodes.size()];

        for(int i=0;i<reportNodes.size();i++){
            ReportNode reptNode = reportNodes.get(i);
            //reportId
            Secs2 reportId = getDataId(reptNode.getReportId(), reptNode.getReportIdType());
            //这个reportId 下面对应的VIDS
            List<Secs2> lz = new ArrayList<>();
            for(ValueNode node:reptNode.getValueList()){
                lz.add(getDataId(node.getValue().toString(), node.getValueType()));
            }
            Secs2List vids = Secs2.list(lz);
            rptList[i] = Secs2.list(reportId, vids);
        }
        ll.add(Secs2.list(rptList));
        return comm.send(2, 33, true, Secs2.list(ll));
    }

    public static Optional<SecsMessage> defineReport(Secs2 s, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {

        return comm.send(2, 33, true, s);
    }

    /**
     * SxFy : s2f35
     * desc : linkEventReport
     * */
    public static Optional<SecsMessage> linkEventReport(List<ReportEventNode> reportEventNodes, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {


        if(reportEventNodes.size()==0){
            //Unlink event report
            List<Secs2> ll = new ArrayList<>();
            ll.add(Secs2.ascii("1"));
            List<Secs2> ls = new ArrayList<>();
            ll.add(Secs2.list(ls));
            return comm.send(2, 35, true, Secs2.list(ll));

        }else {
            List<Secs2> ll = new ArrayList<>();
            //dataid
            ll.add(Secs2.uint2(1));

            Secs2[] rptList = new Secs2[reportEventNodes.size()];

            for(int i=0;i<reportEventNodes.size();i++){
                ReportEventNode reptEventNode = reportEventNodes.get(i);
                //reportId
                Secs2 evetnId = getDataId(reptEventNode.getCeid(), reptEventNode.getCeidType());
                //这个reportId 下面对应的VIDS
                List<Secs2> lz = new ArrayList<>();
                for(ValueNode node:reptEventNode.getValueNodes()){
                    lz.add(getDataId(node.getValue().toString(), node.getValueType()));
                }
                Secs2List vids = Secs2.list(lz);
                rptList[i] = Secs2.list(evetnId, vids);
            }
            ll.add(Secs2.list(rptList));
            return comm.send(2, 35, true, Secs2.list(ll));
        }
    }
    public static Optional<SecsMessage> linkEventReport(Secs2 secs, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {
            return comm.send(2, 35, true, secs);
    }

    /**
     * SxFy : s2f37
     * desc : enable/disable event report
     * */
    public static Optional<SecsMessage> enableEventReport(List<String> ceids,String ceidType,Boolean ceed, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {

        List<Secs2> ll = new ArrayList<>();
        //ceed
        if(ceed){
            ll.add(Secs2.bool(true));
        }else {
            ll.add(Secs2.bool(false));
        }
        List<Secs2> ls = new ArrayList<>();
        for(int i=0 ; i<ceids.size() ; i++){
            ls.add(getDataId(ceids.get(i), ceidType));
        }

        ll.add(Secs2.list(ls));
        return comm.send(2, 37, true, Secs2.list(ll));

    }



    /**
     * SxFy : s2f41
     * desc : host Command send
     * */
    public static Optional<SecsMessage> hostCommandSend(RCMDNode rcmdNode, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {

        if(rcmdNode.getCpArgs()==null || rcmdNode.getCpArgs().size()==0){
            //此次的rcmd 无效
            return null;
        }

        List<Secs2> ll = new ArrayList<>();
        //rcmd-就是远程指令 name
        ll.add(getRCMD(rcmdNode.getRcmd(),rcmdNode.getRcmdType()));
        List<Secs2> ls = new ArrayList<>();
        for(CPArgNode node:rcmdNode.getCpArgs()){
            List<Secs2> lz = new ArrayList<>();
            //cpname
            lz.add(getDataId(node.getCpname(), node.getCpnameType()));
            //cpvalue
            lz.add(getCPVALUE(node.getCpvalue(), node.getCpvalueType()));
            ls.add(Secs2.list(lz));
        }
        ll.add(Secs2.list(ls));

        return comm.send(2, 41, true, Secs2.list(ll));

    }

    /**
     * SxFy : s2f43
     * desc : Reset spooling streams and functions
     *
     * */
    public static Optional<SecsMessage> resetSpoolingSF(List<RestSpoolingNode> sfNodes, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {
        //if m=0 , Reset all spooling streams and functions
        if(sfNodes.size()==0){
            List<Secs2> ll = new ArrayList<>();
            return comm.send(2, 43, true, Secs2.list(ll));
        }else {
            List<Secs2> ll = new ArrayList<>();
            for(RestSpoolingNode node:sfNodes){
                List<Secs2> ls = new ArrayList<>();
                //set stream
                ls.add(Secs2.uint1(node.getStream()));
                //set function
                List<Secs2> lz = new ArrayList<>();
                for(Integer i :node.getFunctions()){
                    lz.add(Secs2.uint1(i));
                }
                ls.add(Secs2.list(lz));

                ll.add(Secs2.list(ls));
            }
            return comm.send(2, 43, true, Secs2.list(ll));
        }





    }

    /**
     * SxFy : s2f49
     * desc : Enhanced Remote Command
     * */
    public static Optional<SecsMessage> enhancedRemoteCommand(ERCMDNode rcmdNode, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {

        if(rcmdNode.getCpArgs()==null || rcmdNode.getCpArgs().size()==0){
            //此次的rcmd 无效
            return null;
        }

        List<Secs2> ll = new ArrayList<>();
        //set dataid
        ll.add(Secs2.uint2(1));
        //set objspec
        ll.add(Secs2.ascii(rcmdNode.getObjspec()));
        //rcmd-就是远程指令 name
        ll.add(getRCMD(rcmdNode.getRcmd(),rcmdNode.getRcmdType()));
        List<Secs2> ls = new ArrayList<>();
        for(CPArgNode node:rcmdNode.getCpArgs()){
            List<Secs2> lz = new ArrayList<>();
            //cpname
            lz.add(getDataId(node.getCpname(), node.getCpnameType()));
            //cpvalue
            lz.add(getCPVALUE(node.getCpvalue(), node.getCpvalueType()));
            ls.add(Secs2.list(lz));
        }
        ll.add(Secs2.list(ls));

        return comm.send(2, 49, true, Secs2.list(ll));
    }


    /**
     * SxFy : s5f3
     * desc : Enable/Disable Alarm Send(S5F3)
     *        如果alid ==null，就代表所有alid enable/disable
     * */
    public static Optional<SecsMessage> alarmEDManager(int[] alid , String alidType ,boolean onoff, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {

        List<Secs2> ll = new ArrayList<>();
        if(onoff){
            ll.add(Secs2.binary((byte) 0x80));
        }else {
            ll.add(Secs2.binary((byte) 0x00));
        }
        ll.add(getDataId(alid,alidType));
        return comm.send(5, 3, true, Secs2.list(ll));
    }


    /**
     * SxFy : s5f5
     * desc : List Alarms Rquest(S5F5)
     *
     * */
    public static Optional<SecsMessage> alarmList(int[] alid , String alidType , HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {

        //alid
        return comm.send(5, 5, true, getDataId(alid,alidType));
    }

    /**
     * SxFy : s6f23
     * desc : Request Spooled Data(S6F23)
     * param :
     *          type :
     *                  0 = Transmit Spooled Messages （请求传输 spooling area 里面的缓存数据，随后有S6F11 陆续发送过来）
     *                  1 = Purge Spooled Messages (清空 spooling area 里面的缓存数据)
     * */
    public static Optional<SecsMessage> requestSpooledData(int type , HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {
        return comm.send(6, 23, true, Secs2.uint1(type));
    }

    /**
     * SxFy : s7f19
     * desc : Current EPPD Request(S7F19) (请求设备当前配方)
     * */
//    public static Optional<SecsMessage> currentEPPDRequest(HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {
//
//        return comm.send(7, 19, true);
//    }
    public static Optional<SecsMessage> currentEPPDRequest(HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {
        try {
            comm.send(7, 19, true);
        }catch (Throwable e){
            e.printStackTrace();
            System.err.println("err s7f19 : "+e.toString());
        }

        return null;
    }

    /**
     * SxFy : s7f5
     * desc : Process Program Request(S7F5) (依据配方id 请求配方)
     * */
    public static Optional<SecsMessage> processProgramRequest(String value,String type,HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {

        return comm.send(7, 5, true,getPPID(value,type));
    }

    /**
     * SxFy : s1f1
     * desc : ping
     * */
    public static boolean areYouThere(HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {

        comm.gem().s1f1();
        return true;
    }

    /**
     * SxFy : s1f13
     * desc : 和设备建立通讯连接
     * return:
     *      0 = Accepted
     *      1 = Denied, Try Again
     * */
    public static COMMACK establishCommunications(HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {
        return comm.gem().s1f13();
    }


    /**
     * SxFy : s1f15
     * desc : 请求离线
     * */
    public static OFLACK requestOffLine(HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {

        return comm.gem().s1f15();
    }

    /**
     * SxFy : s1f17
     * desc : 请求在线
     * */
    public static ONLACK requestOnLine(HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {
        return comm.gem().s1f17();
    }

    /**
     * SxFy : s2f13
     * desc : 设备常量request
     * */
    public static Optional<SecsMessage> eqConstantReq(List<String> ecidList,String ecidType, HsmsSsCommunicator comm) throws InterruptedException, SecsException, Secs2Exception {
        if(ecidList.size()==0){
            return comm.send(2, 13, true, Secs2.list());
        }else {
            List<Secs2> ll = new ArrayList<>();
            for(String vid:ecidList){
                ll.add(getDataId(vid,ecidType));
            }

            return comm.send(2, 13, true, Secs2.list(ll));
        }
    }

}
